// 文章的验证规则

const joi = require('joi')

/**
  title: '标题',
  cate_id: '2',
  content: '内容',
  state: '草稿'
 */
const title = joi.string().required()
const content = joi.string().required().allow('') //允许内容为 空字符串''
const cate_id = joi.number().integer().min(1).required()
const state = joi.string().valid('已发布', '草稿').required()  //只能是'已发布'或者'草稿'

exports.add_article_schema = {
    body: {
        title,
        content,
        cate_id,
        state
    }
}

// 获取文章列表的验证规则
const pagenum = joi.number().integer().min(1).required()
const pagesize = joi.number().integer().min(1).required()
// const get_article_list_cate_id = joi.number().integer().min(1)  //非必填
const get_article_list_cate_id = joi.string().allow('')
const get_article_list_state = joi.string().valid('已发布', '草稿').allow('')  //非必填

exports.get_article_list_schema = {
    query: {
        pagenum,
        pagesize,
        cate_id: get_article_list_cate_id,
        state: get_article_list_state
    }
}

// 根据id删除文章的验证规则
const id = joi.number().integer().required()
exports.delete_article_by_id_schema = {
    params: {
        id
    }
}

// 根据id获取文章详情的规则
exports.get_article_by_id_schema = {
    params: {
        id
    }
}

// 根据id修改文章的表单校验规则
exports.edit_article_by_id_schema = {
    body: {
        Id: id,
        title,
        cate_id,
        content, 
        state
    }
}
